<?php
            


//活动规则
$redrain_rules = [];
$redrain_rule_ids = $_P['redrain_rule_id'];
$redrain_rule_sort = $_P['redrain_rule_sort'];
$redrain_rule_content = $_P['redrain_rule_content'];
if (is_array($redrain_rule_ids)){
    foreach ($redrain_rule_ids as $k =>$v){
        $dd = ['rule_content'=>$redrain_rule_content[$k],'rule_sort'=>$redrain_rule_sort[$k]];
        $redrain_rules[] = $dd;
    }
}
//红包雨时间段
if ($_P['redrain_times']){
    $redrain_times = array_filter($_P['redrain_times']);
}
//if ($_P['redrain_shangjia_num']<1){
//    return_msg('商家赠送机会必须大于0');
//    die();
//}

if ($_P['redrain_alert_icon']){
    $_P['redrain_alert_icon'] = tomedia($_P['redrain_alert_icon']);
}
//判断提现还是抵扣
if ($system['redrain']==2){
    //判断分销是否开启
    if (!$system['fenxiao']){
        return_msg('提现模式下必须开启分销模式');
        die();
    }
    if (!$_P['redrain_alert_icon']){
        $_P['redrain_alert_icon'] = 'https://css2020.yixuan.net//2020css/redrain/home_bg2.png';
    }
}elseif ($system['redrain']==1){
    if (!$_P['redrain_alert_icon']){
        $_P['redrain_alert_icon'] = 'https://css2020.yixuan.net//2020css/redrain/home_bg1.png';
    }
}

if ($_P['redrain_total_amount']>0&&($_P['redrain_total_amount']<$_P['redrain_once_amount'])){
    return_msg('发放红包总金额不可小于每次红包雨发放金额');
    die();
}

//单场红包雨金额不能大于每日上限
if ($_P['redrain_day_amount']>0&&($_P['redrain_day_amount']<$_P['redrain_once_amount'])){
    return_msg('发放红包每日金额不可小于每次红包雨发放金额');
    die();
}

//每日金额不能大于总金额
if($_P['redrain_total_amount']>0&&($_P['redrain_total_amount']<$_P['redrain_day_amount'])){
    return_msg('发放红包总金额不可小于红包雨每日金额');
    die();
}

$min_once_redrain_amount = intval($_P['redrain_redpackage_num'])*0.01;
if ($min_once_redrain_amount>=$_P['redrain_once_amount']){
    return_msg('每场红包雨金额必须大于'.$min_once_redrain_amount);
    die();
}

//抵扣模式判断单个红包金额必须小于支付价格
if($system['redrain']==1){
    $priceArr = [];
    if(sprintf("%.2f",floatval($_P['groupprice'])) > 0){
        array_push($priceArr,sprintf("%.2f",floatval($_P['groupprice'])));
    }
    if(sprintf("%.2f",floatval($_P['groupprice2'])) > 0){
        array_push($priceArr,sprintf("%.2f",floatval($_P['groupprice2'])));
    }
    if(sprintf("%.2f",floatval($_P['groupprice3'])) > 0){
        array_push($priceArr,sprintf("%.2f",floatval($_P['groupprice3'])));
    }
    if(sprintf("%.2f",floatval($_P['primeprice'])) > 0){
        array_push($priceArr,sprintf("%.2f",floatval($_P['primeprice'])));
    }
    if(sprintf("%.2f",floatval($_P['joinfee'])) > 0){
        array_push($priceArr,sprintf("%.2f",floatval($_P['joinfee'])));
    }
    if(empty($priceArr)){
        return_msg('请先设置活动报名金额！');
        die();
    }
    $minPrice = min($priceArr);
    if($minPrice < sprintf("%.2f",floatval($_P['redrain_once_amount']))){
        return_msg('红包雨单个红包金额必须小于活动报名金额！');
        die();
    }
}

$tempconfig=array(
    'redrain_rules' => $redrain_rules,//活动规则
    'redrain_times' => $redrain_times,//活动规则
    'redrain_locationtype' => $_P['redrain_locationtype'],//地区限制类型
    'redrain_city' => $_P['redrain_city'],//限制地区
    'redrain_begintime' => strtotime($_P['redrain_time']['start']),//红包雨开始时间
    'redrain_endtime' => strtotime($_P['redrain_time']['end']),//红包雨结束时间
    'redrain_has_worker'=>intval($_P['redrain_has_worker']),//员工是否参与
    'redrain_min_amount'=>$_P['redrain_min_amount']?$_P['redrain_min_amount']:0.3,//最低提现金额
    'redrain_total_amount'=>$_P['redrain_total_amount'],//本次发放总金额
    'redrain_day_amount'=>$_P['redrain_day_amount'],//每日红包雨发放金额
    'redrain_once_amount'=>$_P['redrain_once_amount'],//每次红包雨发放金额
    'redrain_validity'=>intval(max(0,$_P['redrain_validity'])),//红包使用有效期 小时
    'redrain_help_validity'=>intval(max(1,$_P['redrain_help_validity'])),//助力有效期 小时
    'redrain_chance_limit'=>intval($_P['redrain_chance_limit']),//抽奖机会上限
    'redrain_shangjia_num'=>intval($_P['redrain_shangjia_num']),//商家赠送抽奖机会
    'redrain_first_share_moment'=>intval($_P['redrain_first_share_moment']),//分享朋友圈第一天
    'redrain_second_share_moment'=>intval($_P['redrain_second_share_moment']),//分享朋友圈第二天
    'redrain_third_share_moment'=>intval($_P['redrain_third_share_moment']),//分享朋友圈第三天
    'redrain_first_share_friend'=>intval($_P['redrain_first_share_friend']),//分享好友、群次数 第一天
    'redrain_second_share_friend'=>intval($_P['redrain_second_share_friend']),//分享好友、群 第二天
    'redrain_third_share_friend'=>intval($_P['redrain_third_share_friend']),//分享好友、群 第三天
    'redrain_friend_view_num'=>intval($_P['redrain_friend_view_num']),//几位好友助力
    'redrain_friend_view_limit'=>intval($_P['redrain_friend_view_limit']),//好友助力次数
    'redrain_friend_order_num'=>intval($_P['redrain_friend_order_num']),//好友下单增加几次机会
    'redrain_get_type'=>intval($_P['redrain_get_type']),//提现模式
    'redrain_drop_mode'=>$_P['redrain_drop_mode']?intval($_P['redrain_drop_mode']):0,//下落模式 0 密集 1稀松
    'redrain_speed'=>$_P['redrain_speed']?intval($_P['redrain_speed']):5,//下落速度 5-10 区间
    'redrain_right_icon'=>$_P['redrain_right_icon']?tomedia($_P['redrain_right_icon']):'https://css2020.yixuan.net//2020css/redrain/red_icon.png',
    'redrain_alert_icon'=>$_P['redrain_alert_icon']?tomedia($_P['redrain_alert_icon']):'https://css2020.yixuan.net//2020css/redrain/home_bg1.png',//首页弹屏红包图
);
$config =array_merge($config,$tempconfig);


